package com.netease.financial.internal.di.modules;

import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;

import com.netease.financial.base.login.LoginPresenter;
import com.netease.financial.base.login.LoginPresenterImpl;
import com.netease.financial.common.constant.Constants;
import com.netease.financial.domain.Factory;
import com.netease.financial.domain.executor.PostExecutionThread;
import com.netease.financial.domain.executor.ThreadExecutor;
import com.netease.financial.domain.interactor.GetPageInfo;
import com.netease.financial.domain.interactor.Login;
import com.netease.financial.domain.interactor.UseCase;
import com.netease.financial.domain.repository.NfsRepository;
import com.netease.financial.internal.di.ActivityScope;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Named;

import dagger.Module;
import dagger.Provides;

/**
 * Created by hzwuyufeng on 2/17/16.
 */
@Module
public class LoginModule {

    private static final String PAGE_NAME = "login";
    private final List<String> elements = new ArrayList<>();
    private final Factory<String> mClientId;
    private final Factory<String> mClientSecret;
    private final String mAppSecret;

    public LoginModule(Factory<String> clientId, Factory<String> clientSecret, String appSecret) {
        mClientId = clientId;
        mClientSecret = clientSecret;
        mAppSecret = appSecret;
    }

    @Provides
    @ActivityScope
    LoginPresenter provideLoginPresenter(LoginPresenterImpl loginPresenter) {
        return loginPresenter;
    }

    @Provides
    @ActivityScope
    @Named("login")
    UseCase provideLoginUseCase(NfsRepository nfsRepository, ThreadExecutor threadExecutor, PostExecutionThread postExecutionThread) {
        return new Login(mClientId, mClientSecret, mAppSecret, nfsRepository, threadExecutor, postExecutionThread);
    }

    @Provides
    @ActivityScope
    @Named("page_info")
    UseCase provideGetPageInfoUseCase(Context context, NfsRepository nfsRepository,
                                ThreadExecutor threadExecutor,
                                PostExecutionThread postExecutionThread) {
        DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
        return new GetPageInfo(PAGE_NAME, elements, displayMetrics.widthPixels, displayMetrics.heightPixels,
                Constants.PLATFORM, nfsRepository, threadExecutor, postExecutionThread);
    }

}
